//
//  MainScene.h
//  PlantNanny
//
//  Created by Joueu on 14-12-18.
//
//

#ifndef __PlantNanny__MainScene__
#define __PlantNanny__MainScene__

#include "cocos2d.h"
#include "cocos-ext.h"
#include "Element.h"
#include "BtnPer.h"
#include "XKProgressTimer.h"
#include "ChangeSceneLayer.h"
#include "XKPageView.h"

USING_NS_CC;
USING_NS_CC_EXT;

class MainScene: public Scene, public XKPageViewDelegate,public TableViewDelegate, TableViewDataSource
{
public:
    static MainScene *createScene();
    virtual bool init();
    
private:
    //背景图
    Sprite *windows;
    Sprite *background;
    void createBackground();
    void changeTheTheme(Ref *pSender);
private:
    //菜单
    Layer *m_layer;
    Layer *m_itemsLayer;
    Layer *m_popUpLayer;
    MenuItemImage *m_showSubMenuBtn;
    Menu *m_subMenu;
    Element *m_element;
    BtnPer *m_btnPer;
    
    void elementPressed(Ref *pSender, ui::Button::TouchEventType type);
    void btnPerPressed(Ref *pSender, ui::Button::TouchEventType type);
    void createMenu();
    void createSubMenu();
    void showSubMenuBtnPressed(Ref *pSender);
    void shareBtnPressed(Ref *pSender);
    void btnPressed(Ref *pSender);
    void shopBtnPressed(Ref *pSender);
    void sceneBtnPressed(Ref *pSender);
    void setSubMenuVisible(bool flag);
    void setMenuAndDrinkBtnVisible(bool flag);
private:
    //喝水
    XKProgressTimer *m_progress;
    Sprite *m_bottleBtn;
    void createDrinkBtn();
private:
    //植物和花盆
    Sprite *m_pot;
    Sprite *m_plant;
    void createPlantAndPot();
    
private:
    bool m_moveUp;
    bool m_changScene;
    void createTouchListener();
    void moveUpOrDown(bool flag);
//    XKPageView *cupsPageView;
private:
    //底部的
    Layer *m_bottoLayer;
    void createBottomLayer();
    ValueVector _cupTypeVector;
    ValueVector _cupCapVector;
    TableView *m_tableView;
//    已选水杯
    virtual void tableCellTouched(TableView* table, TableViewCell* cell){};
    virtual TableViewCell* tableCellAtIndex(TableView *table, ssize_t idx) ;
    virtual ssize_t numberOfCellsInTableView(TableView *table);
    virtual Size cellSizeForTable(TableView *table);
    //Delegate
    void addCup(Ref *pSender);
    void deleteCup(Ref *pSender);
    void changeTheDCup(Ref *pSender);
    int _cupType;
private:
    virtual Size sizeForPerPage(XKPageView *pageView);
    ChangeSceneLayer *m_sceneLayer;
private:
    virtual void onEnter();
    virtual void onExit();
    void addCupLayerPopUp(Ref *pSender);
private:
    void preLoadResource();
    void initData();
};

#endif /* defined(__PlantNanny__MainScene__) */
